import {ref,onMounted,onUnmounted,computed} from 'vue'
import request from '../../utils/request'


export default function getData(){  //todoLists
 
    onMounted(async ()=>{
        const data=await request.getAllTodoItems()
        todoLists.value=data
       // console.log(tabList.value[0].todoLists)
    })
 
   const todoLists=ref([])
    const todoTitle = ref('')

    const tabList=computed(()=>{

        const activeTodoList =  todoLists.value.filter(it=>!it.completed);

        const finishedTodoList= todoLists.value.filter(it=>it.completed);

        const activeBadge= activeTodoList.length==0? '':activeTodoList.length

        const completeBadge= finishedTodoList.length==0? '':finishedTodoList.length

        const activeTab={
            badge:activeBadge,
            title:"正在进行",
            datalist:activeTodoList,
            todoLists:todoLists.value
        }
        const compleTab={
            badge:completeBadge,
            title:"已经完成",
            datalist:finishedTodoList,
            todoLists:todoLists.value
        }
        const data=[]
        data.push(activeTab)
        data.push(compleTab)
        return data});




        
    return {
        todoLists,
        todoTitle,
        tabList
    }

}